#include<bits/stdc++.h>
#define int long long
using namespace std;
template <typename T> inline void read(T &x) {
    x = 0; char ch = getchar(); int f = 1;
    while (!isdigit(ch) && ch ^ '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); x *= f;
}
inline void init(){
	freopen("summer.in","r",stdin);
	freopen("summer.out","w",stdout);
}
const int Maxn=1e5+5;
int n,k;
int a[Maxn];
signed main(){
	init();
	read(n);read(k);
	for(int i=1;i<=n;i++)read(a[i]);
	int q;read(q);
	a[0]=a[n+1]=1e18;
	while(q--){
		int x,l,r;read(x);read(l);read(r);
		swap(a[x],a[x+1]);
		int sum=0;
		for(int i=l;i<=r;i++){
			int L=i-1,R=i+1,data=a[i];
			while(L!=0||R!=n+1){
				while(L&&a[L]<=data)L--,sum++;
				while(R<=n&&a[R]<=data)R++,sum++;
				if(L!=0||R!=n+1)sum+=k,data=min(a[L],a[R]);
			}
		}
		printf("%lld\n",sum);
	}
	return 0;
}

